<?php

namespace app\common\model;

use app\common\model\BaseModel as BaseModel;
use ShidianUtil\Utils\ConvertUtil;

/**
 * Class ExternalSource
 * @package app\common\model
 * @property int	$id
 * @property string	$sourceId
 * @property array	$source
 * @property string	$provinceAreasNum
 * @property string	$cityAreasNum
 * @property string $sourceType
 * @property string	$wxStatus
 * @property array	$wxPushMemberIds
 * @property int	$updated
 * @property int	$created
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class ExternalSource extends BaseModel
{
    // 公众号推送状态 UNPUSH 未推送 PUSHING 推送中 PUSHED 已推送
    const UNPUSH = 'UNPUSH';
    const PUSHING = 'PUSHING';
    const PUSHED = 'PUSHED';

    protected $name = 'ExternalSource';

    // 设置json类型字段
    protected $json = ['source'];
    protected $jsonAssoc = true;

    public function getWxPushMemberIdsAttr($value, $data){
        return ConvertUtil::explode($value);
    }

    public function setWxPushMemberIdsAttr($value, $data){
        return ConvertUtil::implode($value);
    }

    /**
     * 1对1
     * @return \think\model\relation\HasOne
     */
    //    public function one(){
    //        return $this->hasOne( Test1::class, 'Test1表中的键', 'ExternalSource表中的键');
    //    }

    /**
     * 1对多
     * @return \think\model\relation\HasMany
     */
    //    public function many(){
    //        return $this->hasMany( Test1::class, 'Test1表中的键', 'ExternalSource表中的键');
    //    }

    /**
     * 多对多
     * @return \think\model\relation\BelongsToMany
     */
    //    public function belongs(){
    //        return $this->belongsToMany( Test1::class, '中间表', '中间表中Test1的键', '中间表中ExternalSource的键');
    //    }
}
